<?php

class UsUsuarioControl extends Controller
{
	public function __construct()
	{
		parent::Controller();

	}
	
	public function index()
	{
		$this->load->view('main',array('content_page' => 'ususuariocontrol_list', 'menutop' => 0));
		
	}
	
	public function data($filtro = FALSE)
	{
		 $page = $this->input->post('page') ? $this->input->post('page') : 1; // Pagina Actual o 1 por default
		 $sortname = $this->input->post('sidx') ? $this->input->post('sidx') : 'id'; // Columna para el order by
		 $sortorder = $this->input->post('sord') ? $this->input->post('sord') : 'desc'; // Orden (asc|desc)
		 $limit = $this->input->post('rows') ? $this->input->post('rows') : 30;

		 $start = $limit * $page - $limit;
		     if($start < 0) $start = 0;
  
		      header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
		      header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
		      header("Cache-Control: no-cache, must-revalidate" );
		      header("Pragma: no-cache" );
		      
		 $records = $this->uscontrolusuariomodel->loadRegistro();
		    
		 $totalRecords = count($records);

		 $totalPages = ceil($totalRecords/$limit);
		     if ($page > $totalPages) 
		       $page = $totalPages;

		    $json_output = array(
		            'page'		=> $page,
		            'total'		=> $totalPages,
		            'records'	=> $totalRecords,
		            'rows'		=> array()
		        );

		    if($records != false){
			     foreach($records as $objetos){

				     $arr = $json_output['rows'][] = array(
				          'id'              => $objetos->getId(),
				          'fecha'       	=> $objetos->getFecha(),
				     	  'idUsuario'       => $objetos->getIdUsuario()
				          
				      );
			      }
		      }

		 echo json_encode($json_output);    
   		
	}
	
}